#!/bin/sh
#
# Workaround for certain power management misfeatures of some harddisks
# Copyright (c) 2012-2020 Michael Buesch <m@bues.ch>
# Licensed for any use.
#

# Regular expression of affected harddisk models
# This regex matches on /sys/block/DISK/device/model
models='(^EZRX)|(^HDS5C)|(^DT01ACA)|(2CX188)'


block="$(hexdump -n 2 -e '/2 "%u"' /dev/urandom)"
for disk in /dev/hd? /dev/sd?; do
	[ -b "$disk" ] || continue
	base="$(basename "$disk")"
	grep -qEe "$models" "/sys/block/$base/device/model" || continue
#	echo "Poking $disk block $block"
	dd if="$disk" of=/dev/null bs=512 count=1 skip="$block" >/dev/null 2>&1
done

exit 0
